package com.dl.code.utils;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * 作者: DL代先生
 * 日期: 2021/5/29
 * 时间: 20:01
 * 内容: Shiro与springboot整合教程！
 * 描述: 获取随机字符串
 */
public class RandomStringUtils {

    /**
     * 获取指定长度的随机字符串
     * @param n
     * @return
     */
    public static String getString(int n){
        StringBuffer stringBuffer = new StringBuffer();
        String string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        char[] charArray = string.toCharArray();
        Random random = new Random();
        int i = 0;
        while (i < n){
            int nextInt = random.nextInt(61);
            stringBuffer.append(charArray[nextInt]);
            i++;
        }
        return stringBuffer.toString();
    }
}
